package com.fc.mall.portal.service.impl;

import com.fc.mall.mapper.PmsBrandMapper;
import com.fc.mall.model.PmsBrand;
import com.fc.mall.model.PmsBrandExample;
import com.fc.mall.portal.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Transactional
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private PmsBrandMapper brandMapper;

    @Override
    public List<PmsBrand> listAllBrand() {
        return brandMapper.selectByExample(new PmsBrandExample());
    }

    @Override
    public PageInfo<PmsBrand> listBrand(String keyword, int pageNum, int pageSize) {
        PmsBrandExample pmsBrandExample = new PmsBrandExample();
        pmsBrandExample.setOrderByClause("sort desc");
        PmsBrandExample.Criteria criteria = pmsBrandExample.createCriteria();
        if (!StringUtils.isEmpty(keyword)) {
            criteria.andNameLike("%" + keyword + "%");
        }
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(brandMapper.selectByExample(pmsBrandExample));
    }
}
